package com.atguigu.yygh.user.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Bruce
 */
@RestController
@RequestMapping("/admin/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Integer page,
                       @PathVariable Integer limit,
                       UserInfoQueryVo userInfoQueryVo){
        IPage<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> model = userInfoService.selectPage(pageParam, userInfoQueryVo);
        return Result.ok(model);
    }

    @ApiOperation(value = "锁定用户")
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable("userId") Long userId, @PathVariable("status") Integer status){
        userInfoService.lock(userId, status);
        return Result.ok();
    }

    @GetMapping("show/{userId}")
    public Result show(@PathVariable Long userId){
        Map<String, Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId, @PathVariable Integer authStatus){
        userInfoService.approval(userId, authStatus);
        return Result.ok();
    }
}
